package cn.pzhu.javadb;
import java.sql.*;
public class DBDemo1 {
	public static void main(String[] args) {
		//1.load dirver
		try {Class.forName("com.mysql.jdbc.Driver");} catch (ClassNotFoundException e) {}
		Connection conn=null;
		PreparedStatement pst=null;
		ResultSet rs=null;
		String url="jdbc:mysql://localhost:3306/2012jb?useUnicode=true&characterEncoding=UTF-8";
		String userName="root";
		String password="123456";
		int minId=2;
		try {//2. connection
			conn=DriverManager.getConnection(url,userName,password);
			//3. statement  or preparestatement
			pst=conn.prepareStatement("SELECT ID,LOGIN_NAME,PASSWORD FROM USER WHERE ID>?");
			pst.setInt(0, minId);
			//4.execute sql ResultSet
			rs=pst.executeQuery();
			//5. data handle
			while(rs.next()){
				System.out.println("ID:"+rs.getInt("ID")
						+"\tLoginName:"+rs.getString("LOGIN_NAME")
						+"\tPassword:"+rs.getString("PASSWORD"));
			}
			
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}finally{
			//6.release resource
			if(rs!=null)try {rs.close();} catch (SQLException e) {}
			if(pst!=null)try {pst.close();} catch (SQLException e) {}
			if(conn!=null)try {conn.close();} catch (SQLException e) {}
		}

	}

}
